package stu.xjtu.physical.common.utls;

import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import stu.xjtu.physical.common.constant.JwtClaimsConstant;
import stu.xjtu.physical.common.properties.JwtProperties;

@Component
@Slf4j
public class JwtHelper {

    @Autowired
    private JwtProperties jwtProperties;
    public Long getFrontUserId(String token) {
        Claims claims = JwtUtil.parseJWT(jwtProperties.getUserSecretKey(), token);
        Long userId = Long.valueOf((Integer) claims.get(JwtClaimsConstant.USER_ID));
        log.info("解析token:{}",userId);
        return userId;
    }
}
